const { model } = require('../db')
const schema = require('../schemas/stu')

class stuModel{ 
    constructor () { 
        this.db = model( 'User', schema );
    }
    store ( data ) { 
        // console.log(data);
        return this.db.insertMany( data );
    }
    find ( data ) { 
        // console.log(data);
        return this.db.find( {del:0});
    }
    search ( data ) { 
        return this.db.find( { username: data.username, del: data.del }, { _id: 0 } );
    }
    del ( data ) { 
        // console.log(data);
        return this.db.updateMany( { _id: data.id }, { $set: { del: 1 } } );
    }
    update ( data ) { 
        // console.log(data);
        return this.db.updateMany( { _id: data._id }, { $set: data } );
         
        
    }
    search ( data ) { 
        return this.db.find( { name: data.name }, { _id: 0 } );
    }
    dim ( data ) { 
        let startDate = data.startTime;
        let endDate = data.endTime;
        let res = this.db.find( { date: { $gte: startDate, $lte: endDate } } );
        return res;
    }
    recover () { 
        return this.db.updateMany( { del: 1 }, { $set: { del: 0 } } );
    }
    check ( data ) { 
        return this.db.updateOne( { _id: data._id }, { $set: { visitor: data.visitor } } )
    }
    alldel () { 
        return this.db.updateMany( { del: 0 }, { $set: { del: 1 } } )
    }
}
module.exports = new stuModel